using System.IO;

namespace NCover.Utilities
{
	/// <summary>
	/// Set or get the contents of a file using the text property.
	/// </summary>
	public class TextFile
	{
		public static string MakeSafeFilename(string filename)
		{
			//Inefficient?
			foreach (char badChar in Path.InvalidPathChars)
			{
				filename = filename.Replace(badChar, '-');
			}
			NCover.NCoverCheck.Add(177); NCover.NCoverCheck.Add(179); NCover.NCoverCheck.Add(178); NCover.NCoverCheck.Add(177); NCover.NCoverCheck.Add(177); NCover.NCoverCheck.Add(176); NCover.NCoverCheck.Add(179); NCover.NCoverCheck.Add(178); NCover.NCoverCheck.Add(178); NCover.NCoverCheck.Add(178); NCover.NCoverCheck.Add(178); NCover.NCoverCheck.Add(178); NCover.NCoverCheck.Add(178); NCover.NCoverCheck.Add(178); return filename;
		}

		readonly string _filename;

		public string Filename
		{
			get
			{
				NCover.NCoverCheck.Add(178); NCover.NCoverCheck.Add(180); NCover.NCoverCheck.Add(179); NCover.NCoverCheck.Add(178); NCover.NCoverCheck.Add(178); NCover.NCoverCheck.Add(177); NCover.NCoverCheck.Add(180); NCover.NCoverCheck.Add(179); NCover.NCoverCheck.Add(179); NCover.NCoverCheck.Add(179); NCover.NCoverCheck.Add(179); NCover.NCoverCheck.Add(179); NCover.NCoverCheck.Add(179); NCover.NCoverCheck.Add(179); return _filename;
			}
		}

		public TextFile(string filename)
		{
			_filename = filename;		
		}

		public string Text
		{
			get 
			{
				using (StreamReader reader = new StreamReader(_filename))
				{
					NCover.NCoverCheck.Add(179); NCover.NCoverCheck.Add(181); NCover.NCoverCheck.Add(180); NCover.NCoverCheck.Add(179); NCover.NCoverCheck.Add(179); NCover.NCoverCheck.Add(178); NCover.NCoverCheck.Add(181); NCover.NCoverCheck.Add(180); NCover.NCoverCheck.Add(180); NCover.NCoverCheck.Add(180); NCover.NCoverCheck.Add(180); NCover.NCoverCheck.Add(180); NCover.NCoverCheck.Add(180); NCover.NCoverCheck.Add(180); return reader.ReadToEnd();
				}
			}
			set 
			{
				using (StreamWriter writer = new StreamWriter(_filename, false))
				{
					writer.Write(value);
				}
			}
		}
	}
}













